<?php
namespace App\models;
use Illuminate\Database\Eloquent\Model;
class Goodscomment extends Model
{

    protected $table = 'goodscomment';
    protected $primaryKey = 'comment_id';
    public $timestamps = false;

    //获取所有商品评论
    public static function selects()
    {
        //关联用户表（user）、商品表（commodity）
        return self::with(['commodity','user'])->get()->toArray();
    }

    //关联商品表
    public function commodity()
    {
        return $this->belongsTo('App\models\Commodity','com_id','com_id');
    }

    //关联用户表
    public function user()
    {
        return $this->belongsTo('App\models\User','com_user_id','user_id');
    }

    //删除商品评论
    public static function dels($id)
    {
        return self::destroy($id);
    }

    //修改商品评论状态
    public static function updates($id,$status)
    {
        if($status==1)
        {
            $c=Goodscomment::find($id);
            $c->com_status='0';
            return $c->save();
        }
        else
        {
            $c=Goodscomment::find($id);
            $c->com_status='1';
            return $c->save();
        }
    }

    //查询单条评论
    public  static function single($id)
    {
        return self::with(['commodity','user'])->find($id);
    }
}
